<template>
	<view class="news">
		<block v-for="news in newsList" :key="news.id">
			<news-item :news="news" @itemClick="toDetail"></news-item>
		</block>
	</view>
</template>

<script>
	import {getNewsList} from '../../api/news/news.js';
	import NewsItem from '../../components/news-item/news-item.vue'
	export default {
		data() {
			return {
				newsList: []
			}
		},
		onLoad() {
			this.getNewsList();
		},
		methods: {
			/**
			 * 获取资讯列表
			 */
			getNewsList() {
				getNewsList().then(res => {
					let newsList = res.data.message;
					this.newsList = newsList;
				})
			},
			/**
			 * 跳转到资讯详情页
			 * @param {Object} id 资讯id
			 */
			toDetail(id) {
				console.log(id)
				uni.navigateTo({
					url: '/pages/news/detail/detail?id=' + id
				});
			}
		},
		components: {
			NewsItem
		}
	}
</script>

<style scoped lang="scss">
	@import '~@/static/css/news/news.scss';
</style>
